﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Utility.Data
{
    public class PasswordProtector
    {
        public static string GetRandomPassword(string username)
        {
            return GetRandomPassword(username, false);
        }

        public static string GetRandomPassword(string username, bool isEncrypt)
        {
            string password = System.Web.Security.Membership.GeneratePassword(10, 3);
            if (isEncrypt)
                return Encrypt(password);
            else
                return password;
        }

        public static string Encrypt(string data)
        {
            return DataSecurity.Encrypt(data, true);
        }

        public static string Decrypt(string data)
        {
            return DataSecurity.Decrypt(data, true);
        }

        public static string Encrypt(string data, string saltkey)
        {
            DataSecurity sec = new DataSecurity(saltkey);
            return sec.EncryptByKey(data);
        }

        public static string Decrypt(string data, string saltkey)
        {
            DataSecurity sec = new DataSecurity(saltkey);
            return sec.DecryptByKey(data);
        }
    }
}